/* app/reducers/list.js */

import { combineReducers } from 'redux';

import reducersProxy from './lib/reducers_proxy';

import { GET_MY_GROUP_LIST,GET_MY_TOPIC_LIST,GET_USER_COLLECT } from '../constants/actionTypes';

let result = {
	state: 2,
	isError: false,
	data: {
		TuanList:{},
		JoinGroupCount:0,
		OpenGroupCount:0
	}
};

function getMyGroupList(typePrefix) {
	return (state = result,action)=>{
		const { type , lists , payload } = action;
		if(type === `${typePrefix}_PENDING` || 
		   type === `${typePrefix}_REJECTED`){
			return action;
		}else if(type === `${typePrefix}_FULFILLED`){
			let { TuanList,JoinGroupCount,OpenGroupCount } = action.data;
			action.data.JoinGroupCount = JoinGroupCount;
			action.data.OpenGroupCount = OpenGroupCount;

			if(TuanList[0]){
				result.data.TuanList[TuanList[0].TopicId] = TuanList;
			}	

			return result;

		}else{
			return state;
		}
	}
}

export default combineReducers({
	myTopicList:reducersProxy('GET_MY_TOPIC_LIST'),
	myGroupList:reducersProxy('GET_MY_GROUP_LIST')
});